﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace client35 {
	/// <summary>
	/// socket type
	/// </summary>
	public enum SocketInfoType {
		DIAL,
		ConnectInfo,
		MsgInfo,
		DIAL_F,
		DTMF,
		PlayMedia,
		HungUp,
		SocketFlag,
		LoadRecordFile,
		BotchRecordFile,
	}

	/// <summary>
	/// deserialize receive message
	/// </summary>
	public class SocketInfo {
		protected SocketInfoType _HeadInfo;
		public SocketInfoType HeadInfo {
			get { return _HeadInfo; }
		}

		protected Hashtable _Content;
		public Hashtable Content {
			get { return _Content; }
		}

		public SocketInfo(string Data) {
			string SocektData = Data.ToString().Replace('-', ':');
			int w = SocektData.IndexOf('{');
			_HeadInfo = (SocketInfoType)Enum.Parse(typeof(SocketInfoType), SocektData.Substring(0, w));
			string information = SocektData.Substring(w + 1, SocektData.Length - w - 2);
			string[] Info = information.Split(';');
			_Content = new Hashtable();
			for (int i = 0; i < Info.Length; i++) {
				if (!string.IsNullOrEmpty(Info[i].ToString())) {
					string[] HTinfo = Info[i].ToString().Split(':');
					Content.Add(HTinfo[0].ToString(), HTinfo[1].ToString());
				}
			}
		}

		public static string GetValueByKey(Hashtable _HashTable, string Key) {
			string values = string.Empty;
			foreach (DictionaryEntry Element in _HashTable) {
				if (Element.Key.ToString() == Key) {
					values = Element.Value.ToString();
				}
			}
			return values;
		}
	}
}
